package com.lesports.qmt.transcode.service.support;

import com.lesports.mongo.repository.MongoCrudRepository;
import com.lesports.qmt.model.support.QmtModel;
import com.lesports.query.InternalQuery;
import com.lesports.utils.QueryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Query;

import java.io.Serializable;
import java.util.List;

/**
 * User: ellios
 * Time: 16-3-20 : 上午11:03
 */
abstract public class AbstractTranscodeService<T extends QmtModel, ID extends Serializable>  {

    protected static final Logger LOG = LoggerFactory.getLogger(AbstractTranscodeService.class);

    protected abstract MongoCrudRepository<T, ID> getInnerRepository();

    public List<T> findByIds(List<ID> ids) {
        return getInnerRepository().findByIds(ids);
    }

    public List<ID> findIdsByQuery(InternalQuery internalQuery) {
        Query query = QueryUtils.buildQuery(internalQuery);
        return getInnerRepository().findIdByQuery(query);
    }

    public List<T> findByQuery(InternalQuery internalQuery) {
        Query query = QueryUtils.buildQuery(internalQuery);
        return getInnerRepository().findByQuery(query);
    }

    public List<ID> findIdByQuery(InternalQuery internalQuery) {
        Query query = QueryUtils.buildQuery(internalQuery);
        return getInnerRepository().findIdByQuery(query);
    }

    public long countByQuery(InternalQuery internalQuery) {
        Query query = QueryUtils.buildQuery(internalQuery);
        return getInnerRepository().countByQuery(query);
    }
}
